//import { Ref } from 'vue'
import { BasicColumn, FormSchema } from "/@/components/Table";
import {render} from '/@/utils/common/renderUtils';

// 列表
export const departTreeColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'departName',
    width: 140,
    align: "left"
  },
  {
    title: '编码',
    dataIndex: 'orgCode',
    width: 60,
  },
  {
    title: '类型',
    dataIndex: 'orgCategory',
    width: 30,
    customRender: ({ text }) => {
      let color = 'red'
      switch (text) {
        case '1':
          color = 'red';
          break;
        case '2':
          color = 'blue';
          break;
        case '3':
          color = 'orange';
          break;
        case '4':
          color = 'green';
          break;
        case '5':
          color = 'pink';
          break;
        case '6':
          color = 'purple';
          break;
      }
      return render.renderTag(render.renderDict(text, 'orgtype'), color);
    },
  },
  {
    title: '排序',
    dataIndex: 'departOrder',
    width: 30,
  },
  {
    title: '描述',
    dataIndex: 'memo',
    width: 120,
  },
]

// 部门基础表单
export function useBasicFormSchema() {
  const basicFormSchema: FormSchema[] = [
    {
      label: 'id',
      field: 'id',
      component: 'Input',
      show: false,
    },
    {
      field: 'orgCategory',
      label: '类型',
      component: 'JDictSelectTag',
      componentProps: { dictCode: 'orgtype', },
      rules: [{ required: true, message: '类型不能为空' }],
    },
    {
      field: 'departName',
      label: '名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入机构/部门名称',
      },
      rules: [{ required: true, message: '名称不能为空' }],
    },
    {
      field: 'parentId',
      label: '上级',
      component: 'TreeSelect',
      componentProps: {
        treeDefaultExpandedKeys: ['98608507967900000'],
        treeData: [],
        placeholder: '无',
        dropdownStyle: { maxHeight: '300px', overflow: 'auto' },
        getPopupContainer: () => document.body,
      },
    },
    {
      field: 'orgCode',
      label: '编码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入机构编码',
      },
    },
    {
      field: 'departOrder',
      label: '排序',
      component: 'InputNumber',
      componentProps: {},
    },
    {
      field: 'linkman',
      label: '微信',
      component: 'JDictSelectTag',
      componentProps: {
        dictCode: 'sf_yn',
        placeholder: '是否在微信通讯录里显示',
      },
    },
    {
      field: 'memo',
      label: '描述',
      component: 'InputTextArea',
      componentProps: {
        placeholder: ' ',
      },
    },
  ]
  return { basicFormSchema }
}

// 机构类型选项
export const orgCategoryOptions = {
  // 一级部门
  root: [{ value: '1', label: '公司' }],
  // 子级部门
  child: [{ value: '2', label: '部门' }, { value: '3', label: '岗位' }],
}
